package gol;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;

import javax.swing.BorderFactory;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;

@SuppressWarnings("serial")
public class testApplet extends JApplet{

	@Override
	public void init(){
		try {
			SwingUtilities.invokeAndWait(new Runnable(){
				@Override
				public void run() {
					JPanel appletPane = new JPanel(new BorderLayout());
					GameOfLife gol = new GameOfLife(new JFrame());
					JScrollPane sp = new JScrollPane(gol);

					sp.getVerticalScrollBar().setUnitIncrement(6);
					sp.getHorizontalScrollBar().setUnitIncrement(6);
					
					gol.addMouseMotionListener(new MouseMotionAdapter() {
						Rectangle r;
						public void mouseDragged(MouseEvent e) {
							r = new Rectangle(e.getX(), e.getY(), 1, 1);
							((GameOfLife) e.getSource()).scrollRectToVisible(r);
						}
					});

					gol.setAutoscrolls(true);
					
					GOLController golPanel = new GOLController(gol);
					appletPane.add(sp, BorderLayout.CENTER);
					appletPane.add(golPanel.getPanel(), BorderLayout.EAST);
					appletPane.setBorder(BorderFactory.createMatteBorder(5, 5, 5, 5, Color.BLACK));
					setContentPane(appletPane);

				}
			});
		} 
		catch (Exception e) {
			e.printStackTrace();
		} 
	}
}
